package tool;

import java.util.*;

public class ReverseHashTable<K, V> extends Hashtable<K,V>{ 
	

	public ReverseHashTable<V,K> getInverse(){
		ReverseHashTable<V,K> h2 = new ReverseHashTable<V,K>();
		Set<K> keys = this.keySet();
		ArrayList<K> kSet = new ArrayList<K>(keys);
		for(K k: kSet){
			h2.put((V)ObjectCloner.deepCopy(this.get(k)),(K)ObjectCloner.deepCopy(k));
		}
		return h2;
	}
	
	public ReverseHashTable clone(){
		Set<K> keys = this.keySet();
		ReverseHashTable<K,V> h = new ReverseHashTable<K,V>();
		
		ArrayList<K> kSet = new ArrayList<K>(keys);
		for(K k: kSet){
			h.put((K)ObjectCloner.deepCopy(k), (V)ObjectCloner.deepCopy(this.get(k)));
		}
		
		return h;
	}
	
	public static void main(String args[]){
		ReverseHashTable<Double,Double> h = new ReverseHashTable<Double,Double>();
		double[] dKey = {0.0,1.0,2.0};
		double[] dVal = {3.0,2.0,1.0};
		for(int i=0;i<dKey.length;i++){
			h.put(new Double(dKey[i]),new Double(dVal[i]));
		}
		System.out.println(h);
		ReverseHashTable<Double,Double> h2 = h.getInverse();
		System.out.println(h2);
		
	}
	
}
